package com.dlc.felear.xiaoensale.customView;

import android.app.Dialog;
import android.content.Context;
import android.support.annotation.NonNull;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

import com.dlc.felear.xiaoensale.R;


public class DoubleSelectDialog extends Dialog implements View.OnClickListener {
    private Button btnCancel, btnConfirm;
    private Context context;
    private AppCompatActivity activity;
    private DoubleSelectCallback callback;
    private int id;
    private int index=1;
    private TextView tv1,tv2;

    public DoubleSelectDialog(@NonNull Context context, DoubleSelectCallback callback) {
        super(context);
        this.callback = callback;
        initView(context);
    }


    public DoubleSelectDialog(@NonNull Context context, int themeResId) {
        super(context, themeResId);
        initView(context);
    }

    private void initView(Context context) {
        this.context = context;
        this.activity = (AppCompatActivity) context;
        View root = LayoutInflater.from(context).inflate(R.layout.double_select_input_dialog, null);
        btnCancel = root.findViewById(R.id.btn_cancel);
        btnConfirm = root.findViewById(R.id.btn_confirm);
        tv1 = root.findViewById(R.id.tv_chaoc);
        tv2 = root.findViewById(R.id.tv_menz);
        btnConfirm.setOnClickListener(this);
        btnCancel.setOnClickListener(this);
        tv1.setOnClickListener(this);
        tv2.setOnClickListener(this);
        setContentView(root);
        setCanceledOnTouchOutside(true);
    }



    public void showDialog(int id) {
        Log.e("ActionHelper","id="+id);
        this.id=id;
        setBgColor(R.id.tv_chaoc);
        show();
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_confirm:
                callback.doubleSelectResult(index,id);
                dismiss();
                break;
            case R.id.btn_cancel:
                dismiss();
                break;
            case R.id.tv_menz:
                setBgColor(R.id.tv_menz);
                index=2;
                break;
            case R.id.tv_chaoc:
                setBgColor(R.id.tv_chaoc);
                index=1;
                break;
            default:
        }
    }

    private void setBgColor(int id){
        tv1.setBackgroundColor(0xffcdcdcd);
        tv2.setBackgroundColor(0xffcdcdcd);
        if(id==R.id.tv_chaoc){
            tv1.setBackgroundColor(0xFF01579B);
        }
        if(id==R.id.tv_menz){
            tv2.setBackgroundColor(0xFF01579B);
        }
    }

    public void setTips(String tips1,String tips2){
    }



    private void  showToast(String msg){
        Toast.makeText(context,msg,Toast.LENGTH_SHORT).show();
    }


    public interface DoubleSelectCallback {
        void doubleSelectResult(int value1, int id);
    }
}
